// import babelpolyfill from 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import VueRouter from 'vue-router'
import routes from './routes'
// import 'font-awesome/css/font-awesome.min.css'
import store from './store/index'
import commonStyle from './common/css/common-style.scss'
import VueI18n from 'vue-i18n'
import En from './assets/lang/en'
import ZhHans from './assets/lang/zh-hans'
import locale from 'element-ui/lib/locale/lang/en'
import zhHans from 'element-ui/lib/locale/lang/zh-CN'

const lang = localStorage.getItem('lang') === 'en' ? locale : zhHans
console.log(localStorage.getItem('lang'))
console.log(lang)

Vue.use(ElementUI, { locale: lang })

// Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.use(commonStyle)
Vue.use(VueI18n)

const router = new VueRouter({
  routes
})

const messages = {
  en: {
    message: En
  },
  zh_hans: {
    message: ZhHans
  }
}

const i18n = new VueI18n({
  locale: localStorage.getItem('lang') || 'zh_hans', // 语言标识
  messages,
  silentTranslationWarn: true
})

router.beforeEach((to, from, next) => {
  if (to.path === '/signIn') {
    localStorage.removeItem('user')
  }
  let user = localStorage.getItem('user')
  if (!user && to.path !== '/signIn') {
    next({ path: '/signIn' })
  } else {
    next()
  }
})

// router.afterEach(transition => {
// NProgress.done();
// });

new Vue({
  // el: '#app',
  // template: '<App/>',
  router,
  store,
  i18n,
  // components: { App }
  render: h => h(App)
}).$mount('#app')
